package com.shizhanzhe.gxb.home.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.shizhanzhe.gxb.R;
import com.shizhanzhe.gxb.home.bean.Merchantlist;
import com.shizhanzhe.gxb.widget.CircleImageView;

import java.util.List;

/**
 * Created by zz9527 on 2018/12/17.
 */
public class MerchantlistAdapter extends BaseAdapter {
    private final LayoutInflater inflater;
    private Context mContext;
    private List<Merchantlist.DataBean.MerchantListResponseBean.MallSearchInfoVoListBean> list;

    public MerchantlistAdapter(List<Merchantlist.DataBean.MerchantListResponseBean.MallSearchInfoVoListBean> list, Context context) {
        this.list = list;
        this.mContext = context;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.adapter_merchantlist, null);
            holder = new ViewHolder();
            holder.headimg = convertView.findViewById(R.id.headimg);
            holder.name = convertView.findViewById(R.id.name);
            holder.item = convertView.findViewById(R.id.item);
            holder.more = convertView.findViewById(R.id.more);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        Merchantlist.DataBean.MerchantListResponseBean.MallSearchInfoVoListBean bean = list.get(i);
        if (!"".equals(bean.getImg_url()) && null != bean.getImg_url()) {
            holder.item.setVisibility(View.VISIBLE);
            holder.more.setVisibility(View.GONE);
            Glide.with(mContext).load(bean.getImg_url()).into(holder.headimg);
            holder.name.setText(bean.getMall_name());
        } else {
            holder.item.setVisibility(View.GONE);
            holder.more.setVisibility(View.VISIBLE);
//            holder.headimg.setImageResource(bean.getMore_img());
        }
        return convertView;
    }

    private static class ViewHolder {
        CircleImageView headimg;
        TextView name;
        LinearLayout item;
        ImageView more;
    }
}

